Eltwise
输入两个等长数组以及控制参数,根据控制参数的值决定对两个数组做对位相加、对位相乘或取最大值操作。
\[\begin{split}\mathbf{output_i} =
\begin{cases}
\mathbf{Input0_i} \cdot \mathbf{Input1_i}, & \text{if } \text{eltwise_mode} = \text{Eltwise_PROD} \\[6pt]
\mathbf{Input0_i} + \mathbf{Input1_i}, & \text{if } \text{eltwise_mode} = \text{Eltwise_SUM} \\[6pt]
\max(\mathbf{Input0_i}, \mathbf{Input1_i}), & \text{if } \text{eltwise_mode} = \text{Eltwise_MAXIMUM}
\end{cases}\end{split}\]
- 输入:
Input0 - 第一个输入数据地址。
Input1 - 第二个输入数据地址。
length - 计算长度。
core_mask(int, 可选) - 核掩码(仅适用于共享存储版本)。
- 输出:
output - 计算结果地址。
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持int8, int16, int32, fp32, fp64, cplx64(除最大值), cplx128(除最大值)
MT7004 支持fp16, fp32, int16, int32, cplx64(除最大值)
共享存储版本:
-
void i8_eltwise_s(int8_t *Input0, int8_t *Input1, int8_t *output, int length, int eltwise_mode_, int core_mask)
-
void i16_eltwise_s(int16_t *Input0, int16_t *Input1, int16_t *output, int length, int eltwise_mode_, int core_mask)
-
void i32_eltwise_s(int *Input0, int *Input1, int *output, int length, int eltwise_mode_, int core_mask)
-
void hp_eltwise_s(half *Input0, half *Input1, half *output, int length, int eltwise_mode_, int core_mask)
-
void fp_eltwise_s(float *Input0, float *Input1, float *output, int length, int eltwise_mode_, int core_mask)
-
void dp_eltwise_s(double *Input0, double *Input1, double *output, int length, int eltwise_mode_, int core_mask)
-
void c64_eltwise_s(float *Input0, float *Input1, float *output, int length, int eltwise_mode_, int core_mask)
-
void c128_eltwise_s(double *Input0, double *Input1, double *output, int length, int eltwise_mode_, int core_mask)
C调用示例:
1//FT78NE示例 2#include <stdio.h> 3#include <eltwise.h> 4#define Eltwise_PROD 0 5#define Eltwise_SUM 1 6#define Eltwise_MAXIMUM 2 7int main(int argc, char* argv[]) { 8 float *input0 = (float *)0xA0000000; //input在DDR空间 9 float *input1 = (float *)0xB0000000; 10 float *output = (float *)0xC0000000; 11 int length = 1000; 12 int eltwise_mode_ = Eltwise_SUM; 13 int core_mask = 0xff; 14 fp_eltwise_s(input0, input1, output, length, eltwise_mode_, core_mask); 15 return 0; 16}
私有存储版本:
-
void i8_eltwise_p(int8_t *Input0, int8_t *Input1, int8_t *output, int eltwise_mode_, int length)
-
void i16_eltwise_p(int16_t *Input0, int16_t *Input1, int16_t *output, int eltwise_mode_, int length)
-
void i32_eltwise_p(int32_t *Input0, int32_t *Input1, int32_t *output, int eltwise_mode_, int length)
-
void hp_eltwise_p(half *Input0, half *Input1, bool *output, int eltwise_mode_, int length)
-
void fp_eltwise_p(float *Input0, float *Input1, float *output, int eltwise_mode_, int length)
-
void dp_eltwise_p(double *Input0, double *Input1, double *output, int eltwise_mode_, int length)
-
void c64_eltwise_p(float *Input0, float *Input1, float *output, int eltwise_mode_, int length)
-
void c128_eltwise_p(double *Input0, double *Input1, double *output, int eltwise_mode_, int length)
C调用示例:
1//FT78NE示例 2#include <stdio.h> 3#include <eltwise.h> 4#define Eltwise_PROD 0 5#define Eltwise_SUM 1 6#define Eltwise_MAXIMUM 2 7 8int main(int argc, char* argv[]) { 9 float *input0 = (float *)0x10810000; //input在L2空间 10 float *input1 = (float *)0x10820000; 11 float *output = (float *)0x10830000; 12 int length = 1000; 13 int eltwise_mode_ = Eltwise_SUM; 14 fp_eltwise_p(input0, input1, output, eltwise_mode_, length); 15 return 0; 16}